package com.xckj.cycling.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.xckj.cycling.R;

/**
 * @Author: ChenYao
 * @Describe: 自定义蓝牙配对Loading
 * @Date: 2023/2/26 18:32
 */
public class BlePairLoadingDialog extends Dialog {
    private Context context;
    public BlePairLoadingDialog(@NonNull Context context) {
        super(context, R.style.fullDialog);
        this.context = context;
    }

    protected BlePairLoadingDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Window window = this.getWindow() ;
        //设置window背景，默认的背景会有Padding值，不能全屏。当然不一定要是透明，你可以设置其他背景，替换默认的背景即可。
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        //一定要在setContentView之后调用，否则无效
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        View view = LayoutInflater.from(context).inflate(R.layout.loading_view_ble_pair, null);
//        setContentView(R.layout.loading_view_ble_pair);
        setContentView(view);
        setCancelable(false);
        setCanceledOnTouchOutside(false);

        view.findViewById(R.id.close).setOnClickListener(view1 -> {
            // 点击关闭按钮
            BlePairLoadingDialog.this.dismiss();
        });
    }
}
